package nci60.data.maxquant.proteingroup
import nci60.data.maxquant.Project
import nci60.data.maxquant.Experiment

/**
 * Information about the identified protein group for each cell line (experiment) <p />
 * (source: proteinGroup.txt)
 *
 * @autor <a href="mailto:Florian.J.Auer@googlemail.com">Florian J. Auer</a>
*/
class ProteinGroupExperiment {

    /**
    * The total number of peptide sequences associated with the protein group (i.e. for all the proteins in the group)
    */
    Integer numberOfPeptides
    
    /**
    * The total number of razor + unique peptides associated with the protein group (i.e. these peptides are shared with another protein group)
    */
    Integer numberOfRazorPeptides
    
    /**
    * The total number of unique peptides associated with the protein group (i.e. these peptides are not shared with another protein group)
    */
    Integer numberOfUniquePeptides
    

    /**
    * number of peptides used for quantification
    */
    Integer numberOfPeptidesForQuantification
    

    /**
    * Percentage of the sequence that is covered by the identified peptides in this sample of the longest protein sequence contained within the group
    */
    Double sequenceCoverage
    
    /**
    * Summed up eXtracted Ion Current (XIC) of all isotopic clusters associated with the identified AA sequence
    * Total intensity of all the isotopic patterns in the label cluster
    */
    Double intensity
    
    /**
    * intensity Based Absolute Quantification (iBAQ)
    */
    Double iBAQ
    
    /**
    * label-free quantification intensity
    */
    Double lfqIntensity
    
    /**
    * number of matching msms spectra
    */
    Integer msmsCount

    /**
    * reference to the cell line (experiment) this protein group information belongs to <p />
    * @see nci60.data.maxquant.Experiment
    */
    Experiment experiment
    
    /**
    * reference to the analysis it belongs to <p />
    * @see nci60.data.maxquant.Project
    */
    Project currentProject

    /**
    * reference to the leading protein entry <p />
    * It is needed for giving entries of this class for a given protein without making all the joins,
    * i.e. from the protein in {@link nci60.data.connected.LeadingProtein} over {@link nci60.data.maxquant.proteingroup.ProteinGroup}.experiments to entries of this class <p />
    * for mapping and resolution issues of the GORM, this association is stored as Integer!
    * @see nci60.data.protein.Protein
    * @see helper.UploadService#updatePeptideIsRazor(java.io.File, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, nci60.data.maxquant.Project)
    */
    Integer protein

    
    /**
    * GRAILS <a href="http://grails.org/doc/latest/guide/GORM.html#gormAssociation" target="_blank">Associations in Gorm</a>
    * <p />
    * <style>.custom-table td{border-top:1pt solid grey;vertical-align:top;} .custom-table{border-collapse:collapse;width:100%;}</style>
    * <table class="custom-table">
    * <tr><td>
    *              group
    * </td><td>        belongs to one specific protein group entry<p />
    *                  <b>See Also:</b> {@link nci60.data.maxquant.proteingroup.ProteinGroup}
    * </td></tr>
    * </table>
    */
    static belongsTo = [group:ProteinGroup]

    /**
     * GRAILS <a href="http://grails.org/doc/latest/guide/single.html#constraints" target="_blank">Declaring Constraints</a>
     * <p />
     * Constraints in Grails are a way to declaratively specify validation rules for generating objects in GORM.
     */	
    static constraints = {
    }


    /**
     * Transforms the attribute values from the MaxQuant input file to values suitable for sql. e.g. "+", and "", are converted into "true", and "false" respectively. <p />
     * This mehtod is used while importing new data.
     * 
     * @param property  name of the property of this class (specified above)
     * @param input     attribute value in the MaxQuant output file
     * @return  replaced sql value of the input
     */	
    static String modifySQL(String property, String input) {
        String output
        if(property=='numberOfPeptidesForQuantification'){
            if(input==''){
                output = '0'
            }else{
                output = input
            }
        }else if(property=='iBAQ'){
            if(input=='NaN'){
                output = '0'
            }else{
                output = input
            }
        }else{
            output = input
        }
        return output
    }
}
